import {
  createApp
} from 'vue'
import {
  createPinia
} from 'pinia'
import App from './App.vue'
// 路由
import router from './router'
// element框架
import ElementPlus from 'element-plus'
// element样式
import 'element-plus/dist/index.css'
// 中文
import zhCn from 'element-plus/es/locale/lang/zh-cn'
// pinia持久化插件
import piniaPluginPersistedstate from 'pinia-plugin-persistedstate'
// 路由守卫
import '@/permission'
// 图标
import '@/styles/icon/iconfont.css'
// 通用的样式
import '@/styles/common/common.css'
// md的样式
import 'md-editor-v3/lib/style.css'
import {
  useUserStore
} from './stores/user'

const app = createApp(App)
// 自定义指令
const permissionDirective = app.directive("permissionDirective", {
  // 会在指令作用的元素插入到页面完成以后触发
  mounted(el, binding) {
    useUserStore().userInfo.token || el.remove()
  }
})
// 注册
app.directive('permissionDirectivem', permissionDirective)
const pinia = createPinia()
pinia.use(piniaPluginPersistedstate)
app.use(pinia)
app.use(router)
app.use(ElementPlus, {
  locale: zhCn
})

app.mount('#app')